<?php

//inculde即可以使用data数据。本页所有的data数据，倾在controller都处理好
include_once("../../../common/module/checkA.php");
include_once("../../../../config.php");
include_once("../controller/collect.php");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
       <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <?php include 'modules/head.php'; ?>



    <style>
        body>.detail-staitics-info .agent-list li{font-size: 12px!important; width:100px;}
        body>.detail-staitics-info .layui-table td, .layui-table th{font-size: 12px!important;}
    </style>






</head>

<body>

<div id="topbar">   <?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?></div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>




        <div id="content">
            <h1>项目统计信息</h1>




            <div class="select-box clearfix layui-form">
                <form action="collect.php?nav-itemed=case" >



                    <div class="layui-form-item">
                        <label class="layui-form-label">周期</label>

                        <div class="layui-input-block">
                            <input type="text" name="select_startday" placeholder="请输入开始时间" autocomplete="off" class="layui-input"  onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" style="float: left; width: 112px" value="<?if($_REQUEST['select_startday']){echo $_REQUEST['select_startday'] ;} ?>" >

                            <span style="float: left;margin: 0 4px; line-height: 30px;">-</span>


                            <input type="text" name="select_endday" placeholder="请输入结束时间" autocomplete="off" class="layui-input" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  style="float: left; width:112px" value="<?if($_REQUEST['select_endday']){echo $_REQUEST['select_endday'] ;} ?>"  >


                            <input type="hidden" name="nav-itemed"  value="case" >


                        </div>


                    </div>









                    <div class="layui-form-item">
                        <label class="layui-form-label">类型</label>

                        <div class="layui-input-block">
                            <select name="at_type" >
                                <option value="0">请选择</option>
                                <?foreach ( $tag_array as $k=>$v){?>
                                <option value="广告工程" <? if($_REQUEST['type']==$v){echo "selected";} ?>> <?echo $v?></option>
                                <?;}?>

                            </select>
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">订单状态</label>

                        <div class="layui-input-block">
                            <select name="status" >
                                <option value="0">全部</option>
                                <option value="完成" <? if($status=="完成"){echo "selected";} ?>>完成</option>
                                <option value="进行中" <? if($status=="进行中"){echo "selected";} ?>>进行中</option>
                                <option value="自然流失" <? if($status=="自然流失"){echo "selected";} ?>>自然流失</option>
                                <option value="我方终止" <? if($status=="我方终止"){echo "selected";} ?>>我方终止</option>
                                <option value="客户终止" <? if($status=="客户终止"){echo "selected";} ?>>客户终止</option>
                                <option value="其他"     <? if($status=="其他"){echo "selected";} ?>>其他</option>
                                <option value="询价中"   <? if($status=="询价中"){echo "selected";} ?>>询价中</option>


                            </select>
                        </div>
                    </div>


                    <button class="layui-btn">查找</button>
                    <button class="layui-btn white" lay-submit lay-filter="formMemberAdd" >清除</button>



                </form>

                <br class="clearfloat"/>
            </div>








            <br class="clearfloat"/>
            <!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
            <div class="list-box">





<h2>年度统计信息</h2>
                <div class="shrinker">以项目开始日期计算</div>

<div class="list-boxes layui-form">



<!--按照项目类型来分-->


                                        <table class="layui-table">
                                            <colgroup>
                                                <col width="80">
                                                <col width="100">
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >

                                            </colgroup>
                                            <thead>


                                            <tr>
                                                <th>序号</th>
                                                <th>新开项目数</th>
                                                <th>完成项目数</th>

                                                <th>新开项目金额</th>
                                                <th>完成项目金额</th>
                                                <th>完成项目利润</th>
                                                <th>完成项目利率</th>

                                                <?foreach ( $tag_array as $k=>$v){?>
                                                <th><?echo $v?></th>
                                                <?;}?>
                                            </tr>
                                            </thead>
                                            <tbody>



<tr >
    <td>本阶段</td>
    <td><?echo count($case_start_list) ?></td>
    <td><?echo count($case_done_list) ?></td>

    <td><? $casecost_array=transform_2darray_in_1darray_number_as_key($case_start_list,"sum");
           echo array_sum($casecost_array)?></td>
    <td><? $case_done_cost_array=transform_2darray_in_1darray_number_as_key($case_done_list,"sum");
        echo array_sum($case_done_cost_array)?></td>
    <td><? $caseprofit_array=transform_2darray_in_1darray_number_as_key($case_done_list,"profit");
        echo array_sum($caseprofit_array)?></td>

    <td><?echo round(array_sum($caseprofit_array)/array_sum($case_done_cost_array)*100,2)?>%</td>


    <?
    $type_list=transform_2darray_in_1darray_number_as_key($case_start_list,"type");
    $condition['data']=$type_list;
    $condition['rang']="like";
    ?>
    <?foreach ( $tag_array as $k=>$v){?>
    <td><? $condition['target']=$v;echo count_num_in_array($condition)?></td>
    <?;}?>


</tr>



<tr >
    <td>本年度</td>
    <td><?echo count($case_year_start_list) ?></td>
    <td><?echo count($case_year_done_list) ?></td>

    <td><? $casecost_year_array=transform_2darray_in_1darray_number_as_key($case_year_start_list,"sum");
        echo array_sum($casecost_year_array)?></td>
    <td><? $case_year_done_cost_array=transform_2darray_in_1darray_number_as_key($case_year_done_list,"sum");
        echo array_sum($case_year_done_cost_array)?></td>
    <td><? $caseprofit_year_array=transform_2darray_in_1darray_number_as_key($case_year_done_list,"profit");
        echo array_sum($caseprofit_year_array)?></td>

    <td><?echo round(array_sum($caseprofit_year_array)/array_sum($case_year_done_cost_array)*100,2)?>%</td>


    <?
    $type_list=transform_2darray_in_1darray_number_as_key($case_year_start_list,"type");
    $condition['data']=$type_list;
    $condition['rang']="like";
    ?>

    <?foreach ( $tag_array as $k=>$v){?>
        <td><? $condition['target']=$v;echo count_num_in_array($condition)?></td>
        <?;}?>


</tr>



    </tbody>
</table>









     <hr/>


    <table class="layui-table">
        <colgroup>
            <col width="80">
            <col width="300">
            <col >
            <col >
            <col >
            <col >
            <col >
            <col >
            <col >
            <col >

        </colgroup>
        <thead>
        <tr>
            <th>序号</th>
            <th>名称</th>
            <th>状态</th>
            <th>时间</th>
            <th>类型</th>
            <th>总额</th>
            <th>利润/利润率</th>
            <th>操作</th>

        </tr>
        </thead>
        <tbody>



                                        <?php


                                            $detail=$case_start_list;

                                        //获取本页用到的单位的名字
                                        $unit_nid_list=transform_2darray_in_1darray_with_new_key($detail,"nid","unit");
                                        $unit_nid_list_str=implode("','",$unit_nid_list);
                                        $unit_list=select_lines_all_items($table_Prefix."unit","","nid in ('".$unit_nid_list_str."')","");
                                        $unit_name_list=transform_2darray_in_1darray_with_new_key($unit_list,"nid","sname");


                                        for ($i = 0; $i < count($detail); $i++) {
                                            ?>



                                            <tr id="item<?echo $detail[$i]['nid']?>" <?if($applymodify['nid']){echo "style='color:red'";$status="审核中";}else{$status="正常";}?>>


                                                <td><?echo $i+1+$plate['page_list_num']*($nowpageid-1) ?></td>
                                                <td>【<?echo $unit_name_list[$detail[$i]['unit']]?>】<?echo $detail[$i]['name']?></td>

                                                <td><span <?if($detail[$i]['status']=='进行中'){echo "style='background-color:#ff9900'";}?>> <?echo $detail[$i]['status']?></span></td>

                                                <td><?echo substr($detail[$i]['startdate'],0,10)?> - <?echo substr($detail[$i]['enddate'],0,10)?> / <?echo count_days($detail[$i]['startdate'],$detail[$i]['enddate'])?> 日 </td>

                                                <td><?echo $detail[$i]['type']?></td>
                                                <td><?echo $detail[$i]['sum']?></td>
                                                <td><?if(isset($detail[$i]['profit']) && ($detail[$i]['status'] =="完成") ){?>
                                                        <? echo $detail[$i]['profit'] ?>  【  <?echo round( $detail[$i]['profit']/$detail[$i]['sum'],3)*100?>% 】
                                                    <?}?></td>



                                                <td>



                                                    <a href="../unit/detail-statistic.php?&nid=<? echo $detail[$i]['unit']?><?echo $pagenumber_url.$sortby_url.$navitemed_url.$system_part.$term_nid ?><?echo $url_str?>"
                                                       class="layui-btn   layui-btn-xs"
                                                       target="_blank vftg bgcbcbc" >信息</a>


                                                    <? if(in_array("admin",$quanxian)){?>
                                                        <a href="detail-edit.php?nid=<? echo $detail[$i]['nid']?><?echo $pagenumber_url.$sortby_url.$navitemed_url.$system_part.$term_nid ?>"
                                                           class="layui-btn   layui-btn-xs">
                                                        <i class="layui-icon">&#xe642;</i>修改
                                                        </a>

                                                    <?}?>



                                                </td>
                                            </tr>
                                        <?}?>


        </tbody>
    </table>


</div>















                <div class="detail-staitics-info"  >


                    <h2>项目收入分析</h2>
                    <div class="shrinker">这里计算的是完结了的项目</div>
                    <div class="layui-form">
                        <table class="layui-table">
                            <colgroup>
                                <col width="100">
                                <col>
                                <col>
                                <col>
                                <col>
                            </colgroup>
                            <thead>
                            <tr>
                                <th>日期</th>
                                <?
                                $type_list=transform_2darray_in_1darray_number_as_key($case_year_start_list,"type");
                                $condition['data']=$type_list;
                                $condition['rang']="like";
                                ?>

                                <?foreach ( $tag_array as $k=>$v){?>
                                    <th><? echo $v?></th>
                                    <?;}?>

                                <th>盈利</th>

                            </tr>
                            </thead>
                            <tbody>


                            <tr>
                                <?$profit=sum_total($table_Prefix."case","profit","paydate like '".date("Y")."%' and status = '完成'");?>
                                <td><b> <?echo date("Y")?></b></td>
                                <?foreach ( $tag_array as $k=>$v){?>
                                    <td><b> <? echo $sum[$k]=sum_total($table_Prefix."case","profit","paydate like '".date("Y")."%' and status = '完成' and type='{$v}' ");?></b> _ <?echo round($sum[$k]/$profit*100,1)?>%</td>
                                <?;}?>
                                <td><?echo array_sum($sum)?></td>
                            </tr>
                            <tr>
                                <?$profit=sum_total($table_Prefix."case","profit","paydate like '".date("Y",strtotime("-1 year "))."%' and status = '完成'");?>
                                <td><b> <?echo date("Y",strtotime("-1 year "))?></b></td>

                                <?foreach ( $tag_array as $k=>$v){?>
                                    <td><b> <? echo $sum[$k]=sum_total($table_Prefix."case","profit","paydate like '".date("Y",strtotime("-1 year "))."%' and status = '完成' and type='{$v}' ");?></b> _ <?echo round($sum[$k]/$profit*100,1)?>%</td>
                                    <?;}?>
                                <td><?echo array_sum($sum)?></td>
                            </tr>


                            <?

                            date_default_timezone_set('Asia/Shanghai');
                            $first_day_of_month = date('Y-m',time()) . '-01 00:00:01';
                            $t = strtotime($first_day_of_month);

                            for($ii=0;$ii<14;$ii++){?>
                                <?$profit=sum_total($table_Prefix."case","profit","paydate like '".date("Y-m",strtotime("-$ii month ",$t))."%' and status = '完成'");?>
                                <tr>
                                    <td><?echo date("Y-m",strtotime("-$ii months",$t))?></td>
                                    <?foreach ( $tag_array as $k=>$v){?>
                                        <td><b> <? echo $sum[$k]=sum_total($table_Prefix."case","profit","paydate like '".date("Y-m",strtotime("-$ii month ",$t))."%' and status = '完成' and type='{$v}' ");?></b> _ <?echo round($sum[$k]/$profit*100,1)?>%</td>
                                        <?;}?>
                                    <td><?echo array_sum($sum)?></td>
                                </tr>


                            <?}?>




                            </tbody>
                        </table>
                    </div>





                <!--list-box end-->
            </div>

            <!--content端點01-->
        </div>
        <!--maincontent端點01-->
        <br class="clearfloat"/>
    </div>
    <!--container端點01-->
</div>









<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
